<%@ page import="dao.AdminD" %>
<%@ page import="dao.UserD" %>
<%@ page import="vo.Admin" %>
<%@ page import="vo.User" %>
<%--
  Created by IntelliJ IDEA.
  User: 007
  Date: 2018/10/25
  Time: 18:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
</head>
<body>
<%
    AdminD adminD = new AdminD();
    UserD userD = new UserD();
    Admin admin = null;
    User user = null;

    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie c : cookies) {
            String cookieName = c.getName();
            if ("name".equals(cookieName)) {
                String cValue = c.getValue();
                try {
                    admin = adminD.findWithId(cValue);
                    user = userD.findWithId(cValue);
                } catch (Exception e) {
                    out.print(e);
                }
                if (admin != null) {
                    session.setAttribute("info", admin);
                    response.sendRedirect("one_page_student");
                    return;
                }
                else if(cValue != null){
                    session.setAttribute("info", user);
                    response.sendRedirect("user/main.jsp");
                    return;
                }
            }
        }
    }
    response.sendRedirect("login.jsp");
%>
</body>
</html>
